# _*_ coding utf-8 _*_
# george
# time: 2025/1/4上午9:28
# name: __init__.py
# comment:

from flask import Flask, request, session, redirect
from .views import common, order, admin


def auth():
    if request.path.startswith("/static"):
        # 所有的静态文件全部不拦截
        return
    if request.path == "/common/login":
        # 继续往后走不做阻拦
        return
    user_info = session.get("user_info")
    if not user_info:
        # 不存在session跳转到登录页面
        return redirect("/common/login")
    return


def create_app():
    app = Flask(__name__)
    # 类似于加盐操作里面的盐
    app.secret_key = "hdhddueueujkdjuceb"
    # 注册蓝图对象
    app.register_blueprint(common.ac)
    app.register_blueprint(order.od)
    app.register_blueprint(admin.admin)

    # 设置拦截器、
    app.before_request(auth)
    return app
